package cn.zhaoyan.servlet;

import cn.zhaoyan.bean.Customer;
import cn.zhaoyan.service.CustomerService;
import cn.zhaoyan.serviceimpl.CustomerServiceipml;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Map;

@WebServlet(urlPatterns = "/Update1Servlet")
public class Update1Servlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=utf-8");
        request.setCharacterEncoding("utf-8");
        Map<String, String[]> parameterMap = request.getParameterMap();
        Customer customer = new Customer();
        BeanUtils beanUtils = new BeanUtils();
        try {
            beanUtils.populate(customer,parameterMap);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }
        CustomerService customerService = new CustomerServiceipml();
         customerService.updateService1(customer);
         request.getRequestDispatcher("/FindServlet").forward(request,response);


    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   doPost(request,response);
    }
}
